package Windows;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

import javax.swing.JScrollPane;

public class PicScrollPanel extends JScrollPane {

	public Image ientered;// 进入背景图片
	public Image iexited;// 离开背景图片
	public boolean entered = false;

	public PicScrollPanel(String iexited) {
		this.iexited = Toolkit.getDefaultToolkit().createImage(iexited);
		this.setOpaque(false);
	}

	public PicScrollPanel(String iexited, String ientered) {
		this(iexited);
		this.ientered = Toolkit.getDefaultToolkit().createImage(ientered);
	}

	/**
	 * 切换背景
	 * 
	 * @param entered
	 */
	public void actionEvent(boolean entered) {
		this.entered = entered;
		updateUI();
	}

	@Override
	public void paintComponent(Graphics g) {
		g.drawImage(entered ? ientered : iexited, 0, 0, this.getWidth(), this.getHeight(), this);
		super.paintComponent(g);
	}

}
